//
//  RCSocketSendSerializationer.m
//  RCNetRequestProject
//
//  Created by kabu on 2017/8/15.
//  Copyright © 2017年 RC. All rights reserved.
//

#import "RCSocketSendSerializationer.h"

@implementation RCSocketSendSerializationer
+ (instancetype)serializationer{
    RCSocketSendSerializationer *ser = [[RCSocketSendSerializationer alloc]init];
    
    return ser;
}
- (NSData*)transformMessageToData:(id)sender{
    if ([sender isKindOfClass:[NSString class]]) {
        NSString *str= sender;
        NSData *data=[str dataUsingEncoding:NSUTF8StringEncoding];
        return data;
    }
    return sender;
}
@end
@implementation RCJsonSocketSendSerializationer
+ (instancetype)serializationer{
    RCJsonSocketSendSerializationer *ser = [[RCJsonSocketSendSerializationer alloc]init];
    
    return ser;
}
- (NSData*)transformMessageToData:(id)sender{
    if ([sender isKindOfClass:[NSDictionary class]]) {
        NSError *error;
        NSData *jsonData=[NSJSONSerialization dataWithJSONObject:sender options:NSJSONWritingPrettyPrinted error:&error];
        if (!error) {
            return jsonData;
        }
    }
    return  [super transformMessageToData:sender];
}

@end
